package org.jeecg.modules.cwysp.service.impl;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import org.jeecg.modules.cwysp.entity.DiyCwysp;
import org.jeecg.modules.cwysp.mapper.DiyCwyspMapper;
import org.jeecg.modules.cwysp.service.IDiyCwyspService;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import java.text.SimpleDateFormat;

/**
 * @Description: 财务预审批
 * @Author: jeecg-boot
 * @Date:   2021-05-09
 * @Version: V1.0
 */
@Service
public class DiyCwyspServiceImpl extends ServiceImpl<DiyCwyspMapper, DiyCwysp> implements IDiyCwyspService {

    @Override
    public void saveOrUpdateInfo(JSONArray form_component_values, String originator_userid) {
        DiyCwysp diyCwysp = new DiyCwysp();
        for (int i = 0; i < form_component_values.size(); i++) {
            JSONObject jsonObject = form_component_values.getJSONObject(i);
            String name = jsonObject.getString("name");
            String value = jsonObject.getString("value");
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");

            switch (name){
                case "老师姓名":
                    diyCwysp.setTeacherName(value);
                    break;
                case "老师工号":
                    diyCwysp.setTeacherNumber(value);
                    break;
                case "报销类型":
                    diyCwysp.setType(value);
                    break;
                case "上传材料":
                    diyCwysp.setFilesString(value);
                    break;
            }
        }


        diyCwysp.setDingUserId(originator_userid);
        System.out.println(diyCwysp);

        //保存
        this.save(diyCwysp);
    }
}
